package com.zr.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.LMuser;
import com.zr.service.UserInfoService;
/**
 * 实现用户登陆
 * @author Administrator
 *
 */
@Controller
@Scope(value="prototype")
public class LoginAction extends ActionSupport implements SessionAware{
	@Resource
	private UserInfoService userinfoservice;
	private Map<String,Object> session;
	
	private String uname;
	private String upsw;
	public String getUname() {
		return uname;
	}
	public void setUname(String uname) {
		this.uname = uname;
	}
	public String getUpsw() {
		return upsw;
	}
	public void setUpsw(String upsw) {
		this.upsw = upsw;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session = arg0;
	}
	/**
	 * 用户登陆的方法
	 * @return
	 */
	public String login(){
		LMuser u = userinfoservice.getCurrentUserInfoByUnameAndUpsw(uname, upsw);
		if(u==null){
			return ERROR;
		}else{
			session.put("user", u);
			return SUCCESS;
		}
	}

}
